Create Project: entity_entity (add Spring Boot Starters from the table)
Create Package: entities (inside main package)
– Create Class: PersonEntity.java (inside package entities)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
PersonEntity.java
package com.ivoronline.entity_entity.entities;
public class PersonEntity {
//PROPERTIES
private Long id;
private String name;
private Integer age;
//SETTERS
public void setId (Long id) { this.id = id; }
public void setName(String name) { this.name = name; }
public void setAge (Integer age) { this.age = age; }
//GETTERS
public Long getId () { return id; }
public String getName() { return name; }
public Integer getAge () { return age; }
}
MyController.java
package com.ivoronline.entity_entity.controllers;
import com.ivoronline.entity_entity.entities.PersonEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
PersonEntity personEntity = new PersonEntity();
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
personEntity.setName("John");
String name = personEntity.getName();
return "Hello " + name;
}
}